<?php
date_default_timezone_set('Asia/Shanghai');
header("Content-type: text/html; charset=utf-8");
error_reporting(E_ALL);
//error_reporting(E_ALL || ~E_NOTICE);
require('db.php');
require('config_db.php');

updeptid();
//更新管辖机构
function updeptid(){

    $sql = "select * FROM Sheet1  where f5 is null";  //1 为采集成功未添加到文章表的数据
    $list = db::get_all($sql);
    if (is_array($list)) {
        foreach ($list as $bminfo) {
           $id=$bminfo['id'];
           $info= db::get_one("select * from seal_main where custname='".$bminfo['f4']."'"); //老表去查询相应信息
          
           if($info){

               $data['f5']=$info['custcode'];
               $data['f6']=$info['principal'];
               $data['f7']=$info['phoneno'];
               $data['f10']=$info['maindealdate'];
               $data['f11']=$info['mainchipdate'];
               db::update("Sheet1", $data, " id=" . $id . "", false);
               echo $id ;
               echo "\n";

               // echo $so_name=$info['so_name'];
               // $infon= db::get_one("select * from system_dept where `name`='".$so_name."'"); //根据老表查询到的 机构名称 去新机构表中查对应名称的信息
               // if($infon){
               //     $newcode=$infon['code'];   //这里是根派出所相同的名称 找出来的新的机构code，对应更新到企业表
               //     if(trim($so_code)===trim($infon['code'])){
               //         echo "挂下机构代码相同";//当 机构代码一致的情况下，不做任何更新操作
               //     }else{
               //         // 机构代码不相同，这里开始更新对应的代码
               //         echo "更新update";
               //         $data['dept_id']=$newcode;
               //         db::update("wl_merchant", $data, " id=" . $id . "", false);
               //         echo "企业".$bminfo['name']. "的管辖机构".$so_name." 代码 ".$dept_id." 更新成 ".$newcode;
               //         file_put_contents("cg.txt","企业".$bminfo['name']. "的管辖机构".$so_name." 代码 ".$dept_id." 更新成 ".$newcode.PHP_EOL, FILE_APPEND);
               //         echo $id ."\n";
               //     }
               // }else{

               //     file_put_contents("error.txt",$bminfo['name']."机构代码 ".$dept_id."对应的派出所名".$so_name."在system_dept中未找到".PHP_EOL, FILE_APPEND);
               // }
           }else{
              
               $data['f15']=1;
               db::update("Sheet1", $data, " id=" . $id . "", false);
               echo $id ;
               echo "\n";

              // file_put_contents("error.txt",$bminfo['name']."机构代码 ".$dept_id."在wl_security_organization中未找到\n".PHP_EOL, FILE_APPEND);
           }
        
        }
    }
}

function pipei($code){


    
   $info= db::get_one("select * from wl_security_organization where so_code='".$code."'");

   if($info){
       $so_code=$info['so_code'];
       echo $so_name=$info['so_name'];

       $infon= db::get_one("select * from system_dept where `name`='".$so_name."'");
      
       if($infon){
           if($so_code==$infon['code']){
               echo "挂下机构代码相同";
           }else{
               echo "更新update";
           }
       }else{
           echo 244334;
       }
   }else{
    echo 222;
   }

}





//更新数据库中的品牌
function uppinpai(){

    $a[]=array("14",'劳力士');
    $a[]=array("15",'DW');
    $a[]=array("16",'江诗丹顿');
    $a[]=array("17",'萧邦');
    $a[]=array("18",'浪琴');
    $a[]=array("19",'卡西欧');
    $a[]=array("20",'欧米茄');
    $a[]=array("21",'阿玛尼');
    $a[]=array("22",'百达翡丽');
    $a[]=array("23",'古驰');
    $a[]=array("24",'Calvin Klein');
    $a[]=array("25",'肖邦');
    $a[]=array("26",'IWC');
    $a[]=array("27",'爱彼');
    $a[]=array("28",'爱马仕');
    $a[]=array("29",'积家');
    $a[]=array("30",'卡地亚');
    $a[]=array("31",'天梭');

    $sql = "select id,title from dxgd_goods where id>44619 limit 4000  ";  //1 为采集成功未添加到文章表的数据
    $list = db::get_all($sql);
    if (is_array($list)) {
        foreach ($list as $bminfo) {
            $id=$bminfo['id'];
            $title=$bminfo['title'];
            for($i=0;$i<count($a);$i++){
                  $ppsd=$a[$i][1];
                  if(strpos($title,$ppsd) !== false){
                      $data['ppid'] =$a[$i][0];
                      break;
                  }
              }
        db::update("dxgd_goods", $data, " id=" . $id . "", false);
        $data=null;
        echo $id ."\n";

        }
    }

}

function deloosfile(){
    $sql = "select * from dxgd_juzi_1 where status=7 limit 2000";  //1 为采集成功未添加到文章表的数据
    $list = db::get_all($sql);

    if (is_array($list)) {
        foreach ($list as $bminfo) {
            $id=$bminfo['id'];
            $content=$bminfo['content'];
            $content=htmlspecialchars_decode($content);
            $content=duanluo::oneKeyArrange($content);
            $tnum=duanluo::strTotal($content);
            $data['content1'] =$content;
            $data['charnum'] =$tnum;
            $data['status'] =8;
            db::update("dxgd_juzi_1", $data, " id=" . $id . "", false);
            echo $id ."\n";
        }
    }

}



function getContent200428($title){
    $pic=$this->getpics();
    $content="";
    $jznum=mt_rand(2,6);
    $list=$this->getrunlist("dxgd_juzi_1",$jznum,"id","content");
    for ($wi = 0; $wi <count($list) ; $wi++) {
        $content=$content."<p class=\"nrpic\"><img src=\"".trim(varray_rand($pic))."\"></p>";
        $content = $content.preg_replace('/{juzi}/', $title, $list[$wi]['content']);
    }
    return $content;
}
